//
//  ShangJiaTableViewCell.m
//  Wedding fantastic
//
//  Created by ZLM on 15/7/2.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ShangJiaTableViewCell.h"

@implementation ShangJiaTableViewCell
-(void)dealloc{
    [_fansLabel release];
    [_nameLabel release];
    [_imageV release];
    [_shoucangButton release];
    [_picUrl release];
    [super dealloc];
}
//重写初始化方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
//创建cell子视图
-(void)createView{
//    商家图片视图
    self.imageV = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 375 * 0.5 * kWidth/375, 98 * kWidth/375)];
    self.imageV.layer.masksToBounds = YES;
//    self.imageV.layer.cornerRadius = 10;
    [self.contentView addSubview:self.imageV];
//   商家名称视图
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.imageV.frame.size.width+10, self.imageV.frame.origin.y+6, 150, 13)];
    self.nameLabel.backgroundColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    self.nameLabel.textColor = [UIColor purpleColor];
    
//    商家粉丝视图
    self.fansLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.imageV.frame.size.width+30, self.nameLabel.frame.size.height+self.nameLabel.frame.origin.y+53, 110, 13)];
    self.fansLabel.backgroundColor = [UIColor whiteColor];
    self.fansLabel.font = [UIFont systemFontOfSize:12];
    
    [self.contentView addSubview:self.fansLabel];
    [self.contentView addSubview:self.nameLabel];
    [self.fansLabel release];
    [self.nameLabel release];

//收藏按钮
    self.shoucangButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.shoucangButton setTitle:@"👍" forState:UIControlStateNormal];
    self.shoucangButton.frame = CGRectMake((375 - 60)*kWidth/375, self.fansLabel.frame.origin.y-2, 60*kWidth/375, 20*kHeight/667);
    self.shoucangButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.shoucangButton setTitleColor:[UIColor brownColor] forState:UIControlStateNormal];
    [self.shoucangButton addTarget:self action:@selector(shoucang:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.shoucangButton];
    //    myCell.textLabel.text = @"Hello World";
    self.backgroundColor = [UIColor whiteColor];
    
}
-(void)shoucang:(UIButton *)shoucangButton{
    
     //   打开数据库
     [[ShangJiaDataBaseHandle shareDataBase]openDB];
     //    创建表
     [[ShangJiaDataBaseHandle shareDataBase]createTable];
     //    获取当前内容
     shangJiaModel *mod = [[shangJiaModel alloc]init];
     mod.name = self.nameLabel.text;
     mod.fans_count = [NSNumber numberWithInteger:[self.fansLabel.text integerValue]];
     mod.logo_path = self.picUrl;
     NSLog(@"!!!!!!!!!!!%@",mod);
    
     //   内容 插入表中
     [[ShangJiaDataBaseHandle shareDataBase]insert:mod];
     
    
    

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
